// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <fmt/core.h>
#include <cstdint>
#include <limits>
#include <string>

namespace kumo::pollux::dwio::common {
    constexpr uint32_t MAX_UINT32 = std::numeric_limits<uint32_t>::max();

    class StreamIdentifier {
    public:
        StreamIdentifier() : id_(MAX_UINT32) {
        }

        explicit StreamIdentifier(int32_t id) : id_(id) {
        }

        virtual ~StreamIdentifier() = default;

        virtual int32_t getId() const {
            return id_;
        }

        virtual bool operator==(const StreamIdentifier &other) const {
            return id_ == other.id_;
        }

        virtual std::size_t hash() const {
            return std::hash<uint32_t>()(id_);
        }

        virtual std::string toString() const {
            return fmt::format("[id={}]", id_);
        }

        /// Returns a special value indicating a stream to be read load quantum by
        /// load quantum.
        static StreamIdentifier sequentialFile() {
            constexpr int32_t kSequentialFile = std::numeric_limits<int32_t>::max() - 1;
            return StreamIdentifier(kSequentialFile);
        }

        int32_t id_;
    };

    struct StreamIdentifierHash {
        std::size_t operator()(const StreamIdentifier &si) const {
            return si.hash();
        }
    };
} // namespace kumo::pollux::dwio::common
